<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>供应商的产品维护</title>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <META content="MSHTML 6.00.2900.5626" name=GENERATOR></HEAD>

<!--<style>
    *{
        background-color: #FFFAE3;
    }

</style>-->
</head>

<body>
<!--//设置的模板-->
<script id="button" type="text/html">
    <button type="button" class="layui-btn layui-btn-sm"  lay-event="del">
        <i  class="layui-icon">删除</i>
    </button>
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;

        //遍历查询出来的结果
        table.render({
            elem: '#demo'
            // ,height: 312
            ,url: '/SuppMaterial/SuppMaterial.html' //数据接口 方法的地址
                ,cellMinWidth: 80
                , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    , groups: 1 //只显示 1 个连续页码
                    , first: false//不显示首页
                    , last: false //不显示尾页
                }
            ,
            cols: [
                [ //表头的字段
                {field: 'material.id', title: 'ID', sort: true, fixed: 'left',
                templet:function (d,value) {
                if (d.material){
                    return d.material.id;
                }else {
                    return  '';
                }
                }
                },
                    {field: 'material.materialNum', title: '物资编码', sort: true,
                        templet:function (d,value) {
                            if (d.material){
                                return d.material.materialNum;

                            }else {
                                return  '';
                            }
                        }
                    },

                    {field: 'material.materialName', title: '物资名称',  sort: true,
                        templet:function (d,value) {
                            if (d.material){
                                return d.material.materialName;
                            }else {
                                return  '';
                            }
                        }
                    },
                    {field: 'material.materialUnit', title: '计量单位',sort: true,
                        templet:function (d,value) {
                            if (d.material){
                                return d.material.materialUnit;

                            }else {
                                return  '';
                            }
                        }

                    },
                    {field: 'material.materialType', title: '物资类别', sort: true,
                    templet:function (d,value) {
                        if (d.material){
                            return d.material.materialType;

                        }else {
                            return  '';
                        }
                    }

                },
                    {field: 'material.quantity', title: '数量',  sort: true,
                        templet:function (d,value) {
                            if (d.material){
                                return d.material.quantity;

                            }else {
                                return  '';
                            }
                        }

                    },
                    {field: 'material.price', title: '价格',  sort: true,
                        templet:function (d,value) {
                            if (d.material){
                                return d.material.price;

                            }else {
                                return  '';
                            }
                        }

                    },
                    {field: 'material.materialdescription', title: '描述', sort: true,
                        templet:function (d,value) {
                            if (d.material){
                                return d.material.materialdescription;

                            }else {
                                return  '';
                            }
                        }

                    }
                ,{title: '操作', toolbar: "#button",align: 'center'}
                ]
            ],id:'tableAll',
        });
        table.on('tool(demo)', function(obj){
            let data = obj.data;
            let mid = data.material.id;
            if(obj.event === 'del'){ //删除
                // var de=layer.confirm("真的删除吗?");
                layer.confirm('确定要删除吗',function (index) {

                  $.ajax({
                      url: "/SuppMaterial/deleteSuppMaterial.html",
                      data:{
                          "mid":mid,
                      },
                      type: "POST",
                      success: function (result) {
                          if(result>0){
                              setTimeout('window.location.reload()',1000);
                          }
                          else{
                              // alert("删除失败");
                              layer.msg('温馨提示，删除失败')

                              this.location.reload();
                          }
                      },
                      async: false
                  })
                    layer.close(index);


            })
            }


        });
        //搜索事件 嗨嗨嗨！
        $('#search').on('click', function(){
            // alert($('#MATERIAL_NUM').val());
            table.reload('tableAll', {
                method : 'get',
                /*url:'/contractmanager/byName',//这个不写表示使用table中的请求*/
                where : {
                    materialNum : $.trim($('#materialNum').val()),
                    materialName : $.trim($('#materialName').val()),
                    orderby : $.trim($('#orderby').val()),
                },
                page : {
                    curr : 1
                }
            });
            return false;
        });
    });
</script>

    <table class="layui-table" cellSpacing=1 cellPadding=3 width="100%" border=1 style="background-color: #FFFAE3">
        <tr bgColor=#FFFAE3>
            <td align=middle width="100%" bgColor=#ffffff colSpan=20 height=22 style="background-color: #FFFAE3">
            <H2>
                <b color=#0070c0 style="font-family: 宋体">供应商的产品维护</b>
            </H2>
            </td>
        </tr>
            <tr>
                <td colspan="9"  align=middle >
                    <form style="background-color: #FFFAE3">
                        产品编号：
<!--                        <div class="layui-input-inline">-->
                        <div class="layui-input-inline">
                         <input type="text" id="materialNum" name="materialNum" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
                        </div>
                         产品名称：  <div class="layui-input-inline">
                          <input type="text" id="materialName" name="materialName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
                        </div>
                        排序方式:
                        <select name="orderby" id="orderby"  style="width: 120px;height: 30px;background-color:#FFFAE3">
                        <option value="m.ID" selected>产品编号</option>
                        <option value="m.MATERIAL_NAME">产品名称</option>
                        <option value="m.price">价格</option>
                        <option value="m.quantity">数量</option>
                    </select>
                        <button  data-type="reload" class="layui-btn" id="search">查询</button>
                    </form>
                </td>
            </tr>
            <tr>
                <td colspan="11" height="100%">
<!--                    添加按钮-->
                    <button type="button" class="layui-btn layui-btn-sm" onclick="javascript:window.location.href='/supplier/supplier_products_add.html'">
                        <i class="layui-icon">新增</i>
                    </button>
                </td>

            </tr>
        <tr><td colspan="11">
            <table  id="demo" lay-filter="demo" width="100%" style="height: 100%" >
            </table>
        </td></tr>
    </table>
</body>
</html>